<!--suppress ALL -->
<include file="./Template/header.html" />
<link rel="stylesheet" type="text/css" href="/Template/css/auditList.css?v=2020102101">
<script type="text/javascript">

    $(function() {

        //初始化页面配置
        initPage("采购单");
        $("body").css("background-color","#ffffff");
        //日期插件
        var start = document.getElementById('startdate');
        start.onfocus = function(){
            this.removeAttribute('placeholder');
        };
        start.onblur = function(){
            if(this.value == '') this.setAttribute('placeholder','开始日期');
        };

        var end = document.getElementById('enddate');
        end.onfocus = function(){
            this.removeAttribute('placeholder');
        };
        end.onblur = function(){
            if(this.value == '') this.setAttribute('placeholder','结束日期');
        };



        var app = new Vue({
            el: '#container',
            data: {
                tempStatus: 0,
                orderList: [],
            },
            methods: {
                dateSearch: function() {
                    var status;
                    $("#my-order ul li").each(function() {
                        if($(this).hasClass("active")) {
                            status = $(this).attr("data-status");
                        }
                    });
                    getOrderList(status);
                },
                dateRefresh: function(str){
                    var start = document.getElementById('startdate');
                    start.value = '';
                    start.setAttribute('placeholder','开始日期');

                    var end = document.getElementById('enddate');
                    end.value = '';
                    end.setAttribute('placeholder','结束日期');
                    var status;
                    $("#my-order ul li").each(function() {
                        if($(this).hasClass("active")) {
                            status = $(this).attr("data-status");
                        }
                    });
                    getOrderList(status);
                },
                getItem: function(str, index){
                    var arr = str.split(',');
                    return arr[index];
                },
                checkRole: function(employeeRoleId, roleId) {
                    var employeeRoleArr = employeeRoleId.split(",");
                    var roleArr = roleId.split(",");

                    var result = false;
                    $.each(roleArr, function(i,val){
                        if($.inArray(val, employeeRoleArr) != -1 || $.inArray((parseInt(val)+100).toString(), employeeRoleArr) != -1){
                            result = true;
                        }
                    });
                    return result;
                },
                auditClaim: function(orderId, status) {
                    var name = "";
                    if(status == 1){
                        name = "审核";
                    }else{
                        name = "反审核";
                    }
                    if(confirm("请确认是否 [" + name + "] 该订单？")) {
                        $.ajax({
                            url: "/wechat/audit/auditPurchase",
                            type: "post",
                            data: {
                                orderId: orderId,
                                status: status,
                            },
                            dataType: "JSON",
                            beforeSend: function () {
                                $("#loadingToast").show();
                            },
                            complete: function () {
                                $('#loadingToast').hide();
                            },
                            success:function(data){
                                if(data.code != 200){
                                    alert(data.message);
                                }
                                window.location.href = "/wechat/audit/purchaseList?status=" + app.tempStatus;
                            },
                            error:function(data){
                                window.location.href = "/wechat/audit/purchaseList?status=" + app.tempStatus;
                            }
                        })
                    }else{
                        return false;
                    }
                },
            }
        })

        function getOrderList(status) {
            $.ajax({
                url:"/wechat/Audit/getPurchaseList",
                type:"post",
                data:{
                    status: status,
                    month: $("#monthList").val(),
                    startdate: $("#startdate").val(),
                    enddate: $("#enddate").val()
                },
                dataType:"JSON",
                beforeSend:function(){
                    $("#loadingToast").show();
                },
                complete:function(){
                    $('#loadingToast').hide();
                },
                success:function(data){
                    app.orderList = data;
                    setTimeout(function() {
                        $(".ui-item.measure-info img").bind("click", function() {
                            var upUrl = "/Template/images/icon-up.png";
                            var downUrl = "/Template/images/icon-down.png";
                            $(this).parent().next().toggle();
                            if($(this).attr("src") == upUrl) {
                                $(this).attr("src", downUrl);
                            } else {
                                $(this).attr("src", upUrl);
                            }
                        });
                        $(".ui-item.measure-info img").each(function() {
                            $(this).trigger("click");
                        });
                    },200);
                },
            })
        }

        $("#my-order ul li").bind("click", function() {

            if($(this).hasClass("active")) {
                return false;
            }

            var status = $(this).attr("data-status");
            app.tempStatus = status;
            $("#my-order ul li").each(function() {
                $(this).removeClass("active");
            });

            $(this).addClass("active");

            getOrderList(status);

        });
        getOrderList('{$orderStatus}');
//        if(isNullOrEmpty("{$orderId}")){
//            getOrderList(0);
//        }else{
//            getOrderList();
//        }

        $(".li-status-1").removeClass("active");
        $(".li-status1").removeClass("active");
//        $(".li-status2").removeClass("active");
        $(".li-status0").removeClass("active");
        switch('{$orderStatus}'){
            case '-1':
                $(".li-status-1").attr("class","active");
                break;
            case '1':
                $(".li-status1").attr("class","active");
                break;
            case '2':
                $(".li-status2").attr("class","active");
                break;
            case '0':
                $(".li-status0").attr("class","active");
                break;
        }

        $("#monthList").change(function() {
            getOrderList(app.tempStatus);
        });

    });


</script>
<div class="container" id="container">
    <div class = "search"  style="height: 3rem">
        <div class="order-add">
            <img class="icon-add" src="/Template/images/icon-searchDate.png" alt="" v-on:click="dateSearch()">
        </div>
        <div class="date-search">
            <input id="startdate" class="date-start" name="startdate" type="date" placeholder="开始日期">
            <input id="enddate" class="date-end" name="enddate" type="date" placeholder="结束日期">
            <img name="refreshImg" class="icon-refreshDate" src="/Template/images/icon-refreshDate.png" alt="" v-on:click="dateRefresh()">
        </div>
        <!--div class="order-month">
            <img class="icon-add" src="/Template/images/icon-approval.png" alt="" v-on:click="auditWorkorderMonth(1)">
        </div>
        <div class="month-search">
            <input id="monthList" class="date-start" name="monthList" type="month" placeholder="审批月份">
        </div-->
    </div>
    <div id="my-order">
        <ul>
            <li class="li-status-1" data-status="-1">
                <span>采购待审核</span>
            </li>
            <!--li class="li-status2" data-status="-2">
                <span>已反审核</span>
            </li-->
            <li class="li-status1" data-status="1">
                <span>已审核</span>
            </li>
            <li class="li-status0 active" data-status="0">
                <span>全部</span>
            </li>
        </ul>
    </div>
    <div class="order-detail">
        <div class="no-data" v-if="orderList == null">暂无数据</div>
        <div class="order-info" v-for="order in orderList">
            <div v-on:click="">
                <!--div class="status active1" v-if="order.outstore_status == -1">
                    <img src="/Template/images/icon-processing.png" alt="">
                    <span class="status-content">待出库</span>
                </div-->
                <div class="status active1" v-if="order.status == -1">
                    <img src="/Template/images/icon-waiting.png" alt="">
                    <span class="status-content">采购待审核</span>
                </div>
                <div class="status active1" v-if="order.status == -2">
                    <img src="/Template/images/icon-unapproval.png" alt="">
                    <span class="status-content">已反审核</span>
                </div>
                <div class="status active1" v-if="order.status == 1">
                    <img src="/Template/images/icon-approval.png" alt="">
                    <span class="status-content">已审核</span>
                </div>

                <div class="have-padding">
                    <div class="user-order-info">
                        <div class="ui-item pickUp-info">
                            <span class="item-left">类型</span>
                            <span class="item-right" style="color: #45a1de;" v-if="order.type == '成品矫形器'">{{order.type}}</span>
                            <span class="item-right" style="color: #1cc385;" v-if="order.type == '物料'">{{order.type}}</span>
                        </div>
                        <div class="ui-item pickUp-info">
                            <span class="item-left">采购单号</span>
                            <span class="item-right">{{order.purchase_no}}</span>
                        </div>
                        <div class="ui-item pickUp-info" v-if="order.supplier_name != '' && order.supplier_name != null">
                            <span class="item-left" >供货商</span>
                            <span class="item-right">{{order.supplier_name}}</span>
                        </div>
                        <div class="ui-item pickUp-info">
                            <span class="item-left">收货仓</span>
                            <span class="item-right">{{order.store_name}}</span>
                        </div>
                        <div class="ui-item pickUp-info">
                            <span class="item-left">采购人</span>
                            <span class="item-right">{{order.purchaser}}: {{order.purchase_date}}</span>
                        </div>
                        <div v-for="purchase in order.orderList">
                            <div v-if="order.type == '成品矫形器'">
                                <div class="ui-item pickUp-info" style="margin-top: 8px">
                                    <span class="item-left" style="color: #45a1de; width: 60%">{{purchase.name}} <img src="{{purchase.image_url}}" style="width:10px;"> [{{purchase.size}}]</span>
                                    <span class="item-right" style="color: #1cc385; width: 35%">{{purchase.number}} {{purchase.unit}}</span>
                                </div>
                                <div class="ui-item pickUp-info" style="margin-bottom: 8px">
                                    <span class="item-left" style="color: #797979;">单价/总价</span>
                                    <span class="item-right" style="color: #e97c7d;">{{purchase.price}}元 / {{purchase.total_price}}元</span>
                                </div>
                            </div>
                            <div v-if="order.type == '物料'">
                                <div class="ui-item pickUp-info" style="margin-top: 8px">
                                    <span class="item-left" style="color: #45a1de; width: 60%">{{purchase.parent_name}}.{{purchase.code_name}}({{purchase.material_name}})</span>
                                    <span class="item-right" style="color: #1cc385; width: 35%">{{purchase.number}} {{purchase.unit}}</span>
                                </div>

                                <div class="ui-item pickUp-info" style="margin-bottom: 8px">
                                    <span class="item-left" style="color: #797979;">单价/总价</span>
                                    <span class="item-right" style="color: #e97c7d;">{{purchase.price}}元 / {{purchase.total_price}}元</span>
                                </div>
                            </div>
                        </div>

                        <div class="ui-item pickUp-info" v-if="order.auditor != '' && order.auditor != null">
                            <span class="item-left">审核人</span>
                            <span class="item-right">{{order.auditor}}: {{order.audit_time}}</span>
                            <!--<span class="item-right" v-if="order.outstore_status != '1'">{{order.auditor_name}}<a style="color: #ee6f61">（未通过）</a></span>-->
                        </div>
                        <div class="ui-item pickUp-info" v-if="order.remark != '' && order.remark != null">
                            <span class="item-left">备注</span>
                            <span class="item-right" style="color: #e97c7d">{{order.remark}}</span>
                            <!--<span class="item-right" v-if="order.outstore_status != '1'">{{order.auditor_name}}<a style="color: #ee6f61">（未通过）</a></span>-->
                        </div>
                        <div class="ui-item pickUp-info" v-if="checkRole('{$user.role}', '4')">
                            <span class="item-left"><button class="deny-button" v-on:click="audit(order.purchase_id, -2)" v-if="order.status == '1'">采购反审核</button></span>
                            <span class="item-right"><button class="approve-button" v-on:click="audit(order.purchase_id, 1)" v-if="order.status == '-1'">采购审核</button></span>
                        </div>
                    </div>
                </div>
            </div>
        </div>

    </div>

</div>

<include file="./Template/footer.html" />

